package front_article_api

import (
	"blog_go/global"
	"blog_go/models"
	"blog_go/models/res"
	"blog_go/service/redis_ser"
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
)

type ArticleDiggRes struct {
	ArticleID uint `json:"article_id"`
}

// 文章点赞
func (ArticleApi) ArticleDigg(c *gin.Context) {
	var req ArticleDiggRes
	if err := c.ShouldBindJSON(&req); err != nil {
		logrus.Error(err)
		panic(err)
	}
	// 查询是否存在
	var article models.ArticleModel
	err := global.DB.First(&article, req.ArticleID).Error
	if err != nil {
		logrus.Error(err)
		panic(err)
	}
	redis_ser.NewArticleDigg().DiggIncr(req.ArticleID)
	res.OkWithMessage("点赞成功", c)
}
